Passed
Push — develop ( a42427...8bd05d )
by Andrew
09:21
created

seomatic-meta.js ➔ seomaticTabChangeHandler   A

Complexity

Conditions 5

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 8
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 30
rs 9.3333
c 0
b 0
f 0
1
/**
2
 * SEOmatic plugin for Craft CMS 3.x
3
 *
4
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
5
 * and flexible
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2017 nystudio107
9
 */
10
11
import SchemaTypeList from "../vue/SchemaTypeList.vue";
12
13
/**
14
 * @author    nystudio107
15
 * @package   SEOmatic
16
 * @since     3.0.0
17
 */
18
19
    if (window.schemaSelectId !== undefined) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 0 spaces, found 4
Loading history...
20
        // Create our vue instance
21
        const vm = new Vue({
0 ignored issues
show
Bug introduced by
The variable Vue seems to be never declared. If this is a global, consider adding a /** global: Vue */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The constant vm seems to be never used. Consider removing it.
Loading history...
22
            el: '#' + window.schemaSelectId,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
23
            components: {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
24
                'schema-type-list': SchemaTypeList,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
25
            },
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
26
            data: {},
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
27
            methods: {},
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
28
            mounted() {
29
            },
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
30
        });
31
    }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 0 spaces, found 4
Loading history...
32
33
// Accept HMR as per: https://webpack.js.org/api/hot-module-replacement#accept
34
if (module.hot) {
35
    module.hot.accept();
36
}
37
38
function seomaticTabChangeHandler() {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
39
    // Tab handler
40
    $('.seomatic-tab-links').on('click', function(e) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
41
        e.preventDefault();
42
        $('.seomatic-tab-links').removeClass('sel');
43
        $(this).addClass('sel');
44
        $('.seomatic-tab-content').addClass('hidden');
45
        var selector = $(this).attr('href');
46
        $(selector).removeClass('hidden');
47
    });
48
}
49
50
window.seomaticTabChangeHandler = seomaticTabChangeHandler;
51
window.seomaticTabChangeHandler();
52
53
$(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
54
    // Show/hide the script settings containers
55
    var selector = $('.seomatic-script-lightswitch').find('.lightswitch');
56
    $(selector).each(function(index, value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
57
        var value = $(this).find('input').first().val();
58
        if (value) {
59
            $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').show();
60
        } else {
61
            $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').hide();
62
        }
63
    });
64
    $(selector).on('click', function(e) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
65
        var value = $(this).find('input').first().val();
66
        if (value) {
67
            $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').slideDown();
68
        } else {
69
            $(this).closest('.seomatic-script-wrapper').find('.seomatic-script-container').slideUp();
70
        }
71
    });
72
73
    // Show/hide the image source fields initially
74
    $('.seomatic-imageSourceSelect > select').each(function(index, value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
75
        var popupValue = $(this).val();
76
        switch (popupValue) {
77
            case 'sameAsSeo':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
78
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').show();
79
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').hide();
80
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').hide();
81
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').hide();
82
                break;
83
84
            case 'fromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
85
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').show();
86
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').show();
87
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').hide();
88
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').hide();
89
                break;
90
91
            case 'fromAsset':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
92
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').show();
93
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').hide();
94
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').show();
95
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').hide();
96
                break;
97
98
            case 'fromUrl':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
99
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').hide();
100
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').hide();
101
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').hide();
102
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').show();
103
                break;
104
        }
105
    });
106
    // Handle hiding/showing the image source fields based on the selection
107
    $('.seomatic-imageSourceSelect > select').on('change', function(e) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
108
        switch (this.value) {
109
            case 'sameAsSeo':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
110
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').slideDown();
111
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').slideUp();
112
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').slideUp();
113
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').slideUp();
114
                break;
115
116
            case 'fromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
117
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').slideDown();
118
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').slideDown();
119
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').slideUp();
120
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').slideUp();
121
                break;
122
123
            case 'fromAsset':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
124
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').slideDown();
125
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').slideUp();
126
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').slideDown();
127
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').slideUp();
128
                break;
129
130
            case 'fromUrl':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
131
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceNotFromUrl').slideUp();
132
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromField').slideUp();
133
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromAsset').slideUp();
134
                $(this).closest('.seomatic-imageSourceWrapper').children('.seomatic-imageSourceFromUrl').slideDown();
135
                break;
136
        }
137
    });
138
139
    // Show/hide the text source fields initially
140
    $('.seomatic-textSourceSelect > select').each(function(index, value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
141
        var popupValue = $(this).val();
142
        switch (popupValue) {
143
            case 'sameAsSeo':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
144
            case 'sameAsGlobal':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
145
            case 'sameAsSiteTwitter':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
146
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').hide();
147
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').hide();
148
                break;
149
150
            case 'fromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
151
            case 'summaryFromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
152
            case 'keywordsFromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
153
            case 'fromUserField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
154
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').show();
155
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').hide();
156
                break;
157
158
            case 'fromCustom':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
159
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').hide();
160
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').show();
161
                break;
162
        }
163
    });
164
    // Handle hiding/showing the image source fields based on the selection
165
    $('.seomatic-textSourceSelect > select').on('change', function(e) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
166
        switch (this.value) {
167
            case 'sameAsSeo':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
168
            case 'sameAsGlobal':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
169
            case 'sameAsSiteTwitter':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
170
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').hide();
171
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').hide();
172
                break;
173
174
            case 'fromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
175
            case 'summaryFromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
176
            case 'keywordsFromField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
177
            case 'fromUserField':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
178
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').show();
179
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').hide();
180
                break;
181
182
            case 'fromCustom':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
183
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromField').hide();
184
                $(this).closest('.seomatic-textSourceWrapper').children('.seomatic-textSourceFromUrl').show();
185
                break;
186
        }
187
    });
188
});
189